<#include "../../select.ftl" />
<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<!DOCTYPE html>
<html>
<head>
    <title>用户管理</title>
    <script type="text/javascript">
        function popAddOrModify(id) {
            var data = {};
            var url = '${absoluteContextPath}/system/user';
            if (id != undefined) {
                data.id = id;
                url = url + "/goEdit";
            } else {
                url = url + "/goAdd";
            }
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        var pop_div = $('#myModal');
                        pop_div.html(data.content.data);
                        pop_div.modal('show');
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }

        function popAssign(userId) {
            var url = '${absoluteContextPath}/system/user/goAssign';
            var data = {};
            data.userId = userId;
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        var pop_div = $('#myModal');
                        pop_div.html(data.content.data);
                        pop_div.modal('show');
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success", mode: "modal"});
                    }
                }
            });
        }

        function popModifyPassword(id) {
            var url = '${absoluteContextPath}/system/user/goModifyPassword';
            var data = {};
            data.id = id;
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        var pop_div = $('#myModal');
                        pop_div.html(data.content.data);
                        pop_div.modal('show');
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }

        function deleteUser() {
            var i = 0;
            $("input[name=ids]").each(function () {
                if ($(this).prop("checked")) {
                    i++;
                }
            });
            if (i == 0) {
                $.showMessage({parentId: "showMessage", message: "请选择您要删除的记录！", type: "success"});
                return false;
            } else {
                $.confirm({
                    confirm: function () {
                        var values = "";
                        $("input[name=ids]").each(function () {
                            if ($(this).prop("checked")) {
                                values += $(this).val() + ",";
                            }
                        });
                        $("#confirmModal").modal("hide");
                        $.post("${absoluteContextPath}/system/user/delete", {
                            'ids': values
                        }, function (data) {
                            data = JSON.parse(data);
                            if (data.returnCode == 1) {
                                $.showMessage({parentId: "showMessage", message: "数据删除成功！", type: "success"});
                                refreshTable();
                            } else {
                                $.showMessage({parentId: "showMessage", message: "数据删除异常！", type: "error"});
                            }
                        });
                    }
                });
            }
        }

        function refreshTable(currentPage) {
            if (currentPage) {
                $("input[name=currentPage]").val(currentPage);
            }
            $("#search_user_table").ajaxSubmit({
                url: '${absoluteContextPath}/system/user/ajaxList',
                beforeSend: showLoading,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $("#tableContent").html(data.content.data);
                    } else {
                        $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
                    }
                }
            });
        }

        function doSelctOrg(target) {
            var orgId = $(target).parent().find("input[name=orgId]").val();
            var orgName = $(target).parent().find("input[name=orgName]").val();
            var data = {};
            var url = '${absoluteContextPath}/system/organization';
            url = url + "/goSelectOrg";
            data.orgId = orgId;
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        var pop_div = $('#myModal2');
                        pop_div.html(data.content.data);
                        pop_div.modal('show');
                        $(pop_div).find("#confirm").click(function () {
                            var ids;
                            var names;
                            $(pop_div).find(".dd-list li").each(function () {
                                if ($(this).attr("data-id") != "0") {
                                    if (this.className.indexOf("dd-active") > 0) {
                                        ids = ($(this).find("input[name=id]:first").val());
                                        names = ($(this).find("input[name=orgName]:first").val());
                                    }
                                }
                            });
                            $(target).parent().find("input[name=orgId]").val(ids);
                            $(target).parent().find("input[name=orgName]").val(names);
                            $('#myModal2').modal("hide");
                        });
                    } else {
                        $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }
    </script>
</head>
<body>

<div class="breadcrumbs">
    <ol class="breadcrumb">
        <li><a href="${absoluteContextPath}/home"><i class="fa fa-home"></i>首页</a></li>
        <li><a href="#">系统管理</a></li>
        <li class="active">用户管理</li>
    </ol>
</div>

<div class="main">
    <!-- row -->
    <div class="row">
        <div class="col-md-12">
            <section class="tile">
                <!-- tile body -->
                <div class="tile-body">
                    <div id="showMessage"><#include "../../message.ftl" /></div>
                    <div class="form-horizontal">
                        <form id="search_user_table" action="${absoluteContextPath}/system/user/list" method="post">
                            <input type="hidden" name="pageSize" value="${usersTable.page.pageSize}"/>
                            <input type="hidden" name="currentPage" value="${usersTable.page.currentPage}"/>

                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">登录名称</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="loginName" value="${userParams.loginName!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">用户名称</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="userName" value="${userParams.userName!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">性别</label>

                                    <div class="col-sm-8">
                                    <@select name="sex" value="${userParams.sex!''}" list=sexTypeList class="form-control"/>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">所属机构ID</label>

                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input name="orgId" value="${userParams.orgId!''}" type="text"
                                                   hidden="true">
                                            <input class="form-control" name="orgName" value="${userParams.orgName!''}"
                                                   placeholder="" type="text" readonly="true">
                                            <span class="input-group-addon" onclick="doSelctOrg(this);"><i
                                                    class="fa fa-search"></i></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">用户状态</label>

                                    <div class="col-sm-8">
                                    <@select name="status" value="${userParams.status!''}" list=userStatusList class="form-control"/>
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">用户类型</label>

                                    <div class="col-sm-8">
                                    <@select name="userType" value="${userParams.userType!''}" list=userTypeList class="form-control"/>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4"></label>

                                    <div class="col-sm-8">
                                        <button type="button" class="btn btn-primary" onclick="refreshTable(1)">查询
                                        </button>
                                        <button type="reset" class="btn btn-default">重置</button>
                                    </div>
                                </div>
                        </form>
                    </div>
                </div>
            </section>
            <section class="tile">
                <div class="tile-header">
                    <h1>
                    <@security.authorize ifAnyGranted="ROLE_USER_A">
                        <button type="button" class="btn btn-green" onclick="popAddOrModify();"><i
                                class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>
                    </@security.authorize>
                    <@security.authorize ifAnyGranted="ROLE_USER_D">
                        <button type="button" class="btn btn-cyan" onclick="deleteUser();"><i class="fa fa-trash-o"></i><span
                                class="margin-left-5">删除</span></button>
                    </@security.authorize>
                    </h1>
                </div>
                <div class="tile-body nopadding">
                    <div class="table-responsive" id="tableContent">
                    <#include "table.ftl"/>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="cardCode04" aria-hidden="true">
</div>
</body>
</html>
